import os

from PublicConstant import (
    database_file,
    search_history_path,
    search_history_section_name,
    thumbnail_path
)


def clear_cache():
    try:
        os.remove(f'{database_file}')
    except FileNotFoundError:
        pass
    with open(f'{search_history_path}', 'w', encoding='utf-8') as f:
        f.write(f'[{search_history_section_name}]')
    for each in os.listdir(thumbnail_path):
        name, ext = os.path.splitext(each)
        if ext != '.jpg':
            continue
        os.remove(f'{thumbnail_path}{each}')


if __name__ == '__main__':
    clear_cache()
